package org.jeecg.modules.user.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.ServiceNameConstants;
import org.jeecg.modules.role.entity.SysUserRole;
import org.jeecg.modules.role.entity.SysUserRoleVO;
import org.jeecg.modules.user.entity.SysUser;
import org.jeecg.modules.user.fallback.SysUserFallback;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Component
@FeignClient(contextId = "SysUserApi", value = ServiceNameConstants.SERVICE_SYSTEM, path = ServiceNameConstants.PATH_SYS_USER, fallback = SysUserFallback.class)
@ConditionalOnMissingClass("org.jeecg.modules.system.controller.SysUserController")
public interface SysUserApi {

    @GetMapping("listByOrg")
    @ApiOperation(value = "根据组织id部门列表获取用户列表")
    Result<IPage<SysUser>> getByOrg(
            @RequestParam(name = "username", required = false) String username,
            @RequestParam(name = "realname", required = false) String realname,
            @RequestParam(name = "orgId", required = false) String orgId,
            @RequestParam(name = "deptId", required = false) List<String> deptIds,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    );

    @PostMapping(value = "save")
    @ApiOperation(value = "保存")
    Result<Boolean> save(@RequestBody SysUser user);


    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户信息")
    Result<SysUser> queryById(@RequestParam(name = "id", required = true) String id);

    @RequestMapping(value = "/addSysUserRole", method = RequestMethod.POST)
    public Result<String> addSysUserRole(@RequestBody SysUserRoleVO sysUserRoleVO);

    @RequestMapping(value = "/deleteUserRole", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除用户角色")
    Result<Boolean> deleteUserRole(@RequestParam(name = "roleId") String roleId,
                                   @RequestParam(name = "userId") String userId);

    @RequestMapping(value = "/deleteUserRoleBatch", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除用户角色")
    public Result<SysUserRole> deleteUserRoleBatch(
            @RequestParam(name = "roleId") String roleId,
            @RequestParam(name = "userIds", required = true) String userIds);
}
